package com.ruoyi.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.demo.domain.EncryptionTable;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface EncryptionTableMapper extends BaseMapper<EncryptionTable> {

    // 获取当前数据库所有的表名
    @Select("SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'camunda'")
    List<Map<String,String>> getTableName();


    // 根据数据库表名获取所有字段
    @Select("SELECT COLUMN_NAME, COLUMN_COMMENT\n" +
            "FROM INFORMATION_SCHEMA.COLUMNS\n" +
            "WHERE TABLE_SCHEMA = 'camunda' AND TABLE_NAME = #{tableName}")
    List<Map<String,String>> getTableColumn(@Param("tableName")String tableName);


    // 根据表名获取数据
    @Select("select ${idColumn},${tableColumn} from ${tableName}")
    List<Map<String,Object>> getDataByTableName(@Param("tableName")String tableName,@Param("tableColumn")String tableColumn,@Param("idColumn")String idColumn);



    /**
     * SM4更新数据
     * @param tableName 表名
     * @param tableColumn   要更新的字段
     * @param idColumn  主键
     * @param idData 主键的值
     * @return
     */
    int updDataByTable(@Param("tableName")String tableName,@Param("tableColumn")Map<String,Object> tableColumn,@Param("idColumn")String idColumn,@Param("idData")String idData);
}
